/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package beans;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import java.sql.*;

@ManagedBean(name="add_user")
@RequestScoped
public class add_user {
    private String username;
    private String password;
    private String authority;
    Connection con;
    Statement statement;
    int updateQuery = 0;
    String SQL_Str;
    

    public String insert(String UName,String Password,String Authority)
    {
        try
        {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db_jsf","root","");
            statement = con.createStatement();
            SQL_Str="INSERT INTO db_jsf.tbl_user (UName,PWord,Authority) VALUES ('" + UName +"','" + Password +"','" + Authority +"')";
            updateQuery = statement.executeUpdate(SQL_Str);
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
            System.out.println("Exception Occur :" + ex);
        }
        if(updateQuery!=0){
            return "inserted";
        }
        else{
            return "error";
        }
    }
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getAuthority() {
        return authority;
    }

    public void setAuthority(String authority) {
        this.authority = authority;
    }
    public String submitUser()
    {
        
        return insert(username,password,authority);
    }
}
